package com.example.day11.homework;


import java.util.concurrent.TimeUnit;

public class MutiplyCount {
    public  static int  sum=0;
    public static void main(String[] args) {

        Thread t1=new TT1();
        Thread t2=new TT2();
        Thread t3=new TT3();
        Thread t4=new TT4();
        Thread t5=new TT5();
        Thread t6=new TT6();
        Thread t7=new TT7();
        Thread t8=new TT8();
        Thread t9=new TT9();
        Thread t10=new TT10();
        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
        t7.start();
        t8.start();
        t9.start();
        t10.start();

        //当前主线程睡眠5秒
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //将各个线程的计数和相加
        MutiplyCount.sum=TT1.sum+TT2.sum+TT3.sum+TT4.sum+TT5.sum+TT6.sum+TT7.sum+TT8.sum+TT9.sum+TT10.sum;

        //输出1-100的和
        System.out.println("1-100之和是："+MutiplyCount.sum);

    }

}
class  TT1 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            //设置每个进程的睡眠时间  每个加100ms
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();
    }

    public  synchronized void  add(){
        for(int i=1;i<=10;i++){
          sum+=i;
        }
    }
}
class  TT2 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();

    }

    public  synchronized void  add(){
        for(int i=11;i<=20;i++){
            sum+=i;
        }
    }
}
class  TT3 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();


    }

    public  synchronized void  add(){
        for(int i=21;i<=30;i++){
            sum+=i;
        }
    }
}
class  TT4 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(400);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();


    }

    public  synchronized void  add(){
        for(int i=31;i<=40;i++){
            sum+=i;
        }
    }
}
class  TT5 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();


    }

    public  synchronized void  add(){
        for(int i=41;i<=50;i++){
            sum+=i;
        }
    }
}
class  TT6 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(600);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();

    }

    public  synchronized void  add(){
        for(int i=51;i<=60;i++){
            sum+=i;
        }
    }
}
class  TT7 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(700);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();


    }

    public  synchronized void  add(){
        for(int i=61;i<=70;i++){
            sum+=i;
        }
    }
}
class  TT8 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(800);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();
    }

    public  synchronized void  add(){
        for(int i=71;i<=80;i++){
            sum+=i;
        }
    }
}
class  TT9 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(900);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();

    }

    public  synchronized void  add(){
        for(int i=81;i<=90;i++){
            sum+=i;
        }
    }
}
class  TT10 extends  Thread{
    public  static  int sum=0;
    @Override
    public void run() {

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        add();


    }


    public  synchronized void  add(){
        for(int i=91;i<=100;i++){
            sum+=i;
        }
    }
}
